package com.ruoyi.mall.app.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.mall.app.service.DtsGoodsProductService;
import com.ruoyi.mall.app.service.DtsGoodsService;
import com.ruoyi.mall.app.service.DtsGoodsSpecificationService;
import com.ruoyi.mall.app.service.DtsIssueService;
import com.ruoyi.mall.common.domain.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/index/goodsDetail")
public class DtsGoodsDetailController extends BaseController {

    @Autowired
    private DtsIssueService dtsIssueService;

    @Autowired
    private DtsGoodsService dtsGoodsService;

    @Autowired
    private DtsGoodsSpecificationService dtsGoodsSpecificationService;

    @Autowired
    private DtsGoodsProductService dtsGoodsProductService;


    // 查询所有常见问题
    @GetMapping("/issue")
    public AjaxResult cateDetailGoodsList(DtsIssue dtsIssue)
    {
        List<DtsIssue> list = dtsIssueService.selectIssueAll(dtsIssue);

        if (list != null){
            return success(list);
        }else {
            return error();
        }
    }

    // 类目id查询商品
    @GetMapping("/seeBoth")
    public AjaxResult seeBoth(long categoryId)
    {
        startPage();
        List<DtsGoods> list = dtsGoodsService.selectGoodsByCategoryId(categoryId);
        if (list != null){
            return success(list);
        }else {
            return error();
        }
    }


    @GetMapping("/specifiction")
    public AjaxResult specifiction(int goodsId)
    {
        // 查询商品规格
        List<DtsGoodsSpecification> list = dtsGoodsSpecificationService.selectGoodsSpecificationCountByGoodsId(goodsId);

        //规格选项
        List<DtsGoodsSpecification> goodsSpecificationList = dtsGoodsSpecificationService.selectGoodsSpecificationByGoodsId(goodsId, list);


        //规格和商品的库存，单价配置

        if (list != null){
            return success(goodsSpecificationList);
        }else {
            return error();
        }

    }


    // 商品规格
    @GetMapping("/temporarilySpecifiction")
    public AjaxResult temporarilySpecifiction(int goodsId)
    {
        startPage();
        List<DtsGoodsProduct> list = dtsGoodsProductService.selectGoodsProductCountByGoodsId(goodsId);
        if (list != null){
            return success(list);
        }else {
            return error();
        }
    }

    // 秒杀商品规格
    @GetMapping("/seckillSpecifiction")
    public AjaxResult seckillSpecifiction(DtsSeckillBatch dtsSeckillBatch)
    {
        List<DtsGoodsProduct> list = dtsGoodsProductService.selectSeckillAndProduct(dtsSeckillBatch);
        if (list != null){
            return success(list);
        }else {
            return error();
        }
    }


    @GetMapping("/addCart")
    public AjaxResult addCart(int goodsId)
    {
        return null;
    }

    // 查询商品库存
    @GetMapping("/goodsStock")
    public AjaxResult goodsStock(int goodsId)
    {
        int stock = dtsGoodsProductService.selectGoodsProductStock(goodsId);
        if (stock != 0){
            return success(stock);
        }else {
            return error();
        }
    }
}
